#!/bin/bash

# File ID: 30375978-63a4-11e0-9d08-00023faf1383

progname=fra_linode
test -e /bellmann.mrk || { echo $progname: Skal kjøres på bellmann. >&2; exit 1; }
lockdir=~/.fra_linode.LOCK

myexit() {
    rmdir $lockdir || echo $progname: $lockdir: Cannot remove lockdir >&2
    exit $1
}

trap "myexit 1" INT TERM
mkdir $lockdir || {
    echo $progname: Ser ut som det kjører en allerede, klarte ikke å mekke lockdir $lockdir >&2;
    exit 1;
}

unset bw
test -z "$1" || bw=" --bwlimit=$1"
echo bw = \"$bw\"

until rsync -avzP$bw --timeout=120 sunny@sunbase.org:dl/til_bellmann/ ~/dl/fra_linode/; do
    echo $progname: rsync failed, retrying...
    sleep 2
done
rmdir $lockdir
